考題日期:2017/09/26
題號:696
星等:2
語言:C++
題目:
題意:
給予一個nxm的棋盤,請問上面最多可以放幾個西洋棋的騎士。
程式:
#include <iostream>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m && m != 0 && n != 0)
{
if(min(n,m)== 1)
cout<<max(n,m)<<" knights may be placed on a "<<n<<" row "<<m<<" column board."<<endl;
else if(min(n,m)==2)
{
int k = max(n,m)/ 4 * 4 + ((max(n,m) % 4 > 1) ? 2 : max(n,m) % 4) * 2;
cout<<k<<" knights may be placed on a "<<n<<" row "<<m<<" column board."<<endl;
}
else
{
cout<<(n * m + 1) / 2<<" knights may be placed on a "<<n<<" row "<<m<<" column board."<<endl;
}
}
return 0;
}
測資: